package data_structure.mooc;

import data_structure.mooc.uf.UnionFind;
import data_structure.mooc.uf.UnionFind3;
import data_structure.mooc.uf.UnionFind4;
import data_structure.mooc.uf.UnionFind5;

import java.util.Random;

public class Test {

    /**
     * 测试类
     * @param uf
     * @param m
     * @return
     */
    public static double testUF(UnionFind uf, int m){
        long startTime=System.nanoTime ();
        int size=uf.getSize ();
        Random random = new Random ();
        for(int i=0;i<m;i++){
            int p=random.nextInt (size);
            int q=random.nextInt (size);
            uf.unionElements (p,q);
        }
        for(int i=0;i<m;i++){
            int p=random.nextInt (size);
            int q=random.nextInt (size);
            uf.isConnected (p,q);
        }
        long endTime = System.nanoTime();
        return (endTime - startTime)/1000_000_000.0;
    }
    public static void main(String[] args) {
        int size=10000;
        int m=1000000;
//        UnionFind1 unionFind1=new UnionFind1 (size);
//        System.out.println("unionFind1:"+testUF (unionFind1,m));
//
//        UnionFind2 unionFind2=new UnionFind2 (size);
//        System.out.println("unionFind2:"+testUF (unionFind2,m));

        UnionFind3 unionFind3=new UnionFind3 (size);
        System.out.println("unionFind3:"+testUF (unionFind3,m));

        UnionFind4 unionFind4=new UnionFind4 (size);
        System.out.println("unionFind4:"+testUF (unionFind4,m));
        UnionFind5 unionFind5 = new UnionFind5(size);
        System.out.println("unionFind5:"+testUF(unionFind5, m));
    }
}
